// additional results

use "output/data.dta", clear
destring id, replace
xtset id time
foreach depvar in extension sprec rotation manage conserv machine pest l_rev l_exp {
	gen `depvar'_bl = L.`depvar'
}
replace yob = 1970 if yob==.

// expenditures by type

rename (exp_wage exp_serv exp_fuel exp_input) (y1 y2 y3 y4)

// training 

foreach depvar in y1 y2 y3 y4 {
	
	poisson `depvar' CAP yob sex res main coop area L.l_exp if time==1 & CAP_ATEG==0, robust
	
	scalar b1`depvar' = _b[CAP]
	loc b1`depvar': display %4.3f b1`depvar'
	scalar se1`depvar' = _se[CAP]
	loc se1`depvar': display %4.3f se1`depvar'
	loc t = _b[CAP]/_se[CAP]
	loc p = 2*ttail((e(N)-e(rank)),abs(`t'))
	loc star1`depvar' = cond(`p'<0.01,"***",cond(`p'<0.05,"**",cond(`p'<0.10,"*","")))
	
}

foreach depvar in y1 y2 y3 y4 {
	
	poisson `depvar' CAP_ATEG yob sex res main coop area L.l_exp if time==1 & CTRL==0, robust
	
	scalar b2`depvar' = _b[CAP_ATEG]
	loc b2`depvar': display %4.3f b2`depvar'
	scalar se2`depvar' = _se[CAP_ATEG]
	loc se2`depvar': display %4.3f se2`depvar'
	loc t = _b[CAP_ATEG]/_se[CAP_ATEG]
	loc p = 2*ttail((e(N)-e(rank)),abs(`t'))
	loc star2`depvar' = cond(`p'<0.01,"***",cond(`p'<0.05,"**",cond(`p'<0.10,"*","")))
	
}

file open Table using "tables/tableS10.tex", write replace
		
file write Table "\begin{table}[h!]" _n 
file write Table "\centering" _n
file write Table "\small" _n
file write Table "\caption{Expenditures by Type}" _n
file write Table "\label{tab:het1}" _n
file write Table "\begin{tabularx} {\linewidth} {@{} l Z Z Z Z}" _n
file write Table "\toprule" _n
file write Table "\toprule" _n
file write Table " & Wages & Services & Fuel & Inputs \\" _n
file write Table "\cmidrule{2-5}" _n		
file write Table " & (1) & (2) & (3) & (4) \\" _n		
file write Table "\midrule" _n
file write Table "\textbf{Panel A: Training} & & & & \\" _n
file write Table "Treatment Effect & `b1y1'`star1y1' & `b1y2'`star1y2' & `b1y3'`star1y3' & `b1y4'`star1y4'  \\" _n
file write Table " & (`se1y1') & (`se1y2') & (`se1y3') & (`se1y4') \\" _n
file write Table " &  &  &  &  \\" _n
file write Table "N & 405 & 405 & 405 & 405 \\" _n
file write Table "\midrule" _n
file write Table "\textbf{Panel B: Technical Assistance} & & & & \\" _n
file write Table "Treatment Effect & `b2y1'`star2y1' & `b2y2'`star2y2' & `b2y3'`star2y3' & `b2y4'`star2y4'  \\" _n
file write Table " & (`se2y1') & (`se2y2') & (`se2y3') & (`se2y4') \\" _n
file write Table " &  &  &  &  \\" _n
file write Table "N & 462 & 462 & 462 & 462 \\" _n
file write Table "\bottomrule" _n
file write Table "\bottomrule" _n
file write Table "\end{tabularx}" _n
file write Table "\begin{tablenotes}" _n
file write Table "\small" _n
file write Table "\begin{spacing}{1.0}" _n
file write Table "\item Notes: {Each row reports the results for a different outcome. Column 1 reports the coefficient of a bivariate regression of each outcome on the dummy indicating that the farm was offered technical assistance. Column 2 adds the outcome itself measured in the baseline as a control. Column 3 adds the pre-determined characteristics as additional controls. The sample is restricted to farmers who completed the training. Robust standard errors are reported in parentheses. *** p<0.01; ** p<0.05; * p<0.10}" _n
file write Table "\end{spacing}" _n
file write Table "\end{tablenotes}" _n
file write Table "\end{table}%" _n
file close Table

// output, output per animal and number of animals

cap drop y1 y2 y3 y4
rename (l_exp l_exp_ani l_ani) (y1 y2 y3)

// training

foreach depvar in y1 y2 y3 {

	reg `depvar' CAP yob sex res main coop area L.y1 if time==1 & CAP_ATEG==0 & y2!=., robust
	
	scalar b1`depvar' = _b[CAP]
	loc b1`depvar': display %4.3f b1`depvar'
	scalar se1`depvar' = _se[CAP]
	loc se1`depvar': display %4.3f se1`depvar'
	loc t = _b[CAP]/_se[CAP]
	loc p = 2*ttail(e(df_r),abs(`t'))
	loc star1`depvar' = cond(`p'<0.01,"***",cond(`p'<0.05,"**",cond(`p'<0.10,"*","")))
	
}

// technical assistance

foreach depvar in y1 y2 y3 {

	reg `depvar' CAP_ATEG yob sex res main coop area L.y1 if time==1 & CTRL==0 & y2!=., robust
	
	scalar b2`depvar' = _b[CAP_ATEG]
	loc b2`depvar': display %4.3f b2`depvar'
	scalar se2`depvar' = _se[CAP_ATEG]
	loc se2`depvar': display %4.3f se2`depvar'
	loc t = _b[CAP_ATEG]/_se[CAP_ATEG]
	loc p = 2*ttail(e(df_r),abs(`t'))
	loc star2`depvar' = cond(`p'<0.01,"***",cond(`p'<0.05,"**",cond(`p'<0.10,"*","")))
	
}

file open Table using "tables/tableS11.tex", write replace
		
file write Table "\begin{table}[h!]" _n 
file write Table "\centering" _n
file write Table "\small" _n
file write Table "\caption{Productivity Measures}" _n
file write Table "\label{tab:het1}" _n
file write Table "\begin{tabularx} {\linewidth} {@{} l Z Z Z Z}" _n
file write Table "\toprule" _n
file write Table "\toprule" _n
file write Table " & log(Exp.) & log(Exp. / Heads) & log(Heads) \\" _n
file write Table "\cmidrule{2-4}" _n		
file write Table " & (1) & (2) & (3) \\" _n		
file write Table "\midrule" _n
file write Table "\textbf{Panel A: Training} & & & \\" _n
file write Table "Treatment Effect & `b1y1'`star1y1' & `b1y2'`star1y2' & `b1y3'`star1y3' \\" _n
file write Table " & (`se1y1') & (`se1y2') & (`se1y3') \\" _n
file write Table " &  &  &  \\" _n
file write Table "N & 355 & 355 & 355 \\" _n
file write Table "\midrule" _n
file write Table "\textbf{Panel B: Technical Assistance} & & & \\" _n
file write Table "Treatment Effect & `b2y1'`star2y1' & `b2y2'`star2y2' & `b2y3'`star2y3' \\" _n
file write Table " & (`se2y1') & (`se2y2') & (`se2y3') \\" _n
file write Table " &  &  & \\" _n
file write Table "N & 414 & 414 & 414 \\" _n
file write Table "\bottomrule" _n
file write Table "\bottomrule" _n
file write Table "\end{tabularx}" _n
file write Table "\begin{tablenotes}" _n
file write Table "\small" _n
file write Table "\begin{spacing}{1.0}" _n
file write Table "\item Notes: {Each row reports the results for a different outcome. Column 1 reports the coefficient of a bivariate regression of each outcome on the dummy indicating that the farm was offered technical assistance. Column 2 adds the outcome itself measured in the baseline as a control. Column 3 adds the pre-determined characteristics as additional controls. The sample is restricted to farmers who completed the training. Robust standard errors are reported in parentheses. *** p<0.01; ** p<0.05; * p<0.10}" _n
file write Table "\end{spacing}" _n
file write Table "\end{tablenotes}" _n
file write Table "\end{table}%" _n
file close Table

// revenues

// training 

foreach model in 1 2 3 {
	
	if `model' == 1 {
		loc spec reg l_rev CAP if time==1 & CAP_ATEG==0, robust
	}
	else if `model' == 2 {
		loc spec reg l_rev CAP yob sex res main coop area if time==1 & CAP_ATEG==0, robust
	}	
	else if `model' == 3 {
		loc spec reg l_rev CAP yob sex res main coop area L.l_rev if time==1 & CAP_ATEG==0, robust
	}	
		
	`spec'
	scalar b1y`model' = _b[CAP]
	loc b1y`model': display %4.3f b1y`model'
	scalar se1y`model' = _se[CAP]
	loc se1y`model': display %4.3f se1y`model'
	loc t = _b[CAP]/_se[CAP]
	loc p = 2*ttail(e(df_r),abs(`t'))
	loc star1y`model' = cond(`p'<0.01,"***",cond(`p'<0.05,"**",cond(`p'<0.10,"*","")))
	scalar n1y`model' = e(N)
	loc n1y`model': display %3.0f n1y`model'

				
}

// technical assistance

foreach model in 1 2 3 {
	
	if `model' == 1 {
		loc spec reg l_rev CAP_ATEG if time==1 & CTRL==0, robust
	}
	else if `model' == 2 {
		loc spec reg l_rev CAP_ATEG yob sex res main coop area if time==1 & CTRL==0, robust
	}	
	else if `model' == 3 {
		loc spec reg l_rev CAP_ATEG yob sex res main coop area L.l_rev if time==1 & CTRL==0, robust
	}	
		
	`spec'
	scalar b2y`model' = _b[CAP_ATEG]
	loc b2y`model': display %4.3f b2y`model'
	scalar se2y`model' = _se[CAP_ATEG]
	loc se2y`model': display %4.3f se2y`model'
	loc t = _b[CAP_ATEG]/_se[CAP_ATEG]
	loc p = 2*ttail(e(df_r),abs(`t'))
	loc star2y`model' = cond(`p'<0.01,"***",cond(`p'<0.05,"**",cond(`p'<0.10,"*","")))
	scalar n2y`model' = e(N)
	loc n2y`model': display %3.0f n2y`model'
			
}

file open Table using "tables/tableS12.tex", write replace
		
file write Table "\begin{table}[h!]" _n 
file write Table "\centering" _n
file write Table "\small" _n
file write Table "\caption{Revenues}" _n
file write Table "\label{tab:het1}" _n
file write Table "\begin{tabularx} {\linewidth} {@{} l Z Z Z Z}" _n
file write Table "\toprule" _n
file write Table "\toprule" _n		
file write Table " & (1) & (2) & (3) \\" _n		
file write Table "\midrule" _n
file write Table "\textbf{Panel A: Training} & & & \\" _n
file write Table "Treatment Effect & `b1y1'`star1y1' & `b1y2'`star1y2' & `b1y3'`star1y3' \\" _n
file write Table " & (`se1y1') & (`se1y2') & (`se1y3') \\" _n
file write Table " &  &  &  \\" _n
file write Table "N & `n1y1' & `n1y2' & `n1y3' \\" _n
file write Table "\midrule" _n
file write Table "\textbf{Panel B: Technical Assistance} & & & \\" _n
file write Table "Treatment Effect & `b2y1'`star2y1' & `b2y2'`star2y2' & `b2y3'`star2y3' \\" _n
file write Table " & (`se2y1') & (`se2y2') & (`se2y3') \\" _n
file write Table " &  &  & \\" _n
file write Table "N & `n2y1' & `n2y2' & `n2y3' \\" _n
file write Table "\midrule" _n
file write Table "Demographic Controls & No & Yes & Yes \\" _n
file write Table "Baseline Dep. Var. & No & No & Yes \\" _n
file write Table "\bottomrule" _n
file write Table "\bottomrule" _n
file write Table "\end{tabularx}" _n
file write Table "\begin{tablenotes}" _n
file write Table "\small" _n
file write Table "\begin{spacing}{1.0}" _n
file write Table "\item Notes: {Each row reports the results for a different outcome. Column 1 reports the coefficient of a bivariate regression of each outcome on the dummy indicating that the farm was offered technical assistance. Column 2 adds the outcome itself measured in the baseline as a control. Column 3 adds the pre-determined characteristics as additional controls. The sample is restricted to farmers who completed the training. Robust standard errors are reported in parentheses. *** p<0.01; ** p<0.05; * p<0.10}" _n
file write Table "\end{spacing}" _n
file write Table "\end{tablenotes}" _n
file write Table "\end{table}%" _n
file close Table

// land use

cap drop y1 y2 y3 
rename (sreser sidle sexpl spast sagric spd) (y1 y2 y3 y4 y5 y6)

// training

foreach depvar in y1 y2 y3 y4 y5 y6 {

	reg `depvar' CAP yob sex res main coop area L.`depvar' if time==1 & CAP_ATEG==0, robust
	
	scalar b1`depvar' = _b[CAP]
	loc b1`depvar': display %4.3f b1`depvar'
	scalar se1`depvar' = _se[CAP]
	loc se1`depvar': display %4.3f se1`depvar'
	loc t = _b[CAP]/_se[CAP]
	loc p = 2*ttail(e(df_r),abs(`t'))
	loc star1`depvar' = cond(`p'<0.01,"***",cond(`p'<0.05,"**",cond(`p'<0.10,"*","")))
	
}

// technical assistance

foreach depvar in y1 y2 y3 y4 y5 y6 {

	reg `depvar' CAP_ATEG yob sex res main coop area L.`depvar' if time==1 & CTRL==0, robust
	
	scalar b2`depvar' = _b[CAP_ATEG]
	loc b2`depvar': display %4.3f b2`depvar'
	scalar se2`depvar' = _se[CAP_ATEG]
	loc se2`depvar': display %4.3f se2`depvar'
	loc t = _b[CAP_ATEG]/_se[CAP_ATEG]
	loc p = 2*ttail(e(df_r),abs(`t'))
	loc star2`depvar' = cond(`p'<0.01,"***",cond(`p'<0.05,"**",cond(`p'<0.10,"*","")))
	
}

file open Table using "tables/tableS13.tex", write replace
		
file write Table "\begin{table}[h!]" _n 
file write Table "\centering" _n
file write Table "\small" _n
file write Table "\caption{Land Use}" _n
file write Table "\label{tab:het1}" _n
file write Table "\begin{tabularx} {\linewidth} { l Z Z Z Z Z Z}" _n
file write Table "\toprule" _n
file write Table "\toprule" _n
file write Table " & Reserves & Idle & Expl. & Pasture & Crop & No-till \\" _n
file write Table "\cmidrule{2-7}" _n		
file write Table " & (1) & (2) & (3) & (4) & (5) & (6) \\" _n		
file write Table "\midrule" _n
file write Table "\textbf{Panel A: Training} & & & & & & \\" _n
file write Table "Treatment Effect & `b1y1'`star1y1' & `b1y2'`star1y2' & `b1y3'`star1y3' & `b1y4'`star1y4' & `b1y5'`star1y5' & `b1y6'`star1y6' \\" _n
file write Table " & (`se1y1') & (`se1y2') & (`se1y3') & (`se1y4') & (`se1y5') & (`se1y6') \\" _n
file write Table " &  &  &  & & & \\" _n
file write Table "N & 465 & 465 & 465 & 465 & 465 & 465 \\" _n
file write Table "\midrule" _n
file write Table "\textbf{Panel B: Technical Assistance} & & & & & & \\" _n
file write Table "Treatment Effect & `b2y1'`star2y1' & `b2y2'`star2y2' & `b2y3'`star2y3' & `b2y4'`star2y4' & `b2y5'`star2y5' & `b2y6'`star2y6' \\" _n
file write Table " & (`se2y1') & (`se2y2') & (`se2y3') & (`se2y4') &  (`se2y5') &  (`se2y6') \\" _n
file write Table " &  &  &  & & & \\" _n
file write Table "N & 528 & 528 & 528 & 528 & 528 & 528 \\" _n
file write Table "\bottomrule" _n
file write Table "\bottomrule" _n
file write Table "\end{tabularx}" _n
file write Table "\begin{tablenotes}" _n
file write Table "\small" _n
file write Table "\begin{spacing}{1.0}" _n
file write Table "\item Notes: {Each row reports the results for a different outcome. Column 1 reports the coefficient of a bivariate regression of each outcome on the dummy indicating that the farm was offered technical assistance. Column 2 adds the outcome itself measured in the baseline as a control. Column 3 adds the pre-determined characteristics as additional controls. The sample is restricted to farmers who completed the training. Robust standard errors are reported in parentheses. *** p<0.01; ** p<0.05; * p<0.10}" _n
file write Table "\end{spacing}" _n
file write Table "\end{tablenotes}" _n
file write Table "\end{table}%" _n
file close Table		

